package sueca2011;

import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
import java.io.File;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 *
 * @author gabrieloliveira
 */
public class TelaJogo extends javax.swing.JFrame implements Observer{
    private Jogo jogo;
    private Jogador jogador;
    private ArrayList<Carta> cartas;
    private String imgFolder;

    /** Creates new form TelaJogo */
    public TelaJogo(Jogo jogo, Jogador jogador) throws RemoteException {
        jogo.addObserverNasRodadas(this);
        imgFolder = new File("img").getAbsolutePath()+File.separator;
        //imgFolder = this.getClass().getResource("img").toString()+File.separator;
        //imgFolder = imgFolder.substring(imgFolder.indexOf(":")+1, imgFolder.length());
        //System.out.println(imgFolder);
        this.jogo = jogo;
        this.jogador = jogador;
        this.cartas = this.jogador.getCartasIniciais();
        initComponents();
        nome1.setText("");
        nome2.setText("");
        nome3.setText("");
        nome4.setText("");
        nomeDonoTrunfo.setText(jogo.getDonoTrunfo().getNome());
        vez.setText("");
        vez1.setText("");

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        try{
            carta1 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(0).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta2 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(1).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta3 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(2).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta4 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(3).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta6 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(5).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta7 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(6).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta8 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(7).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta9 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(8).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta10 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(9).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        try{
            carta5 = new JButton(new ImageIcon(imgFolder+jogador.getCartasIniciais().get(4).imageURL()));
            ;
        }catch(RemoteException ex){
            ex.printStackTrace();
        }
        start = new javax.swing.JButton();
        cartaTrunfo = new JButton(new ImageIcon(imgFolder+jogo.getTrunfo().imageURL()));
        ;
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jogada1 = new JButton();
        ;
        jogada2 = new JButton();
        ;
        jogada3 = new JButton();
        ;
        jogada4 = new JButton();
        ;
        nome1 = new javax.swing.JLabel();
        nome2 = new javax.swing.JLabel();
        nome3 = new javax.swing.JLabel();
        nome4 = new javax.swing.JLabel();
        vez = new javax.swing.JLabel();
        nomeDonoTrunfo = new javax.swing.JLabel();
        vez1 = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sueca2011.JogoApp.class).getContext().getResourceMap(TelaJogo.class);
        jLayeredPane1.setBackground(resourceMap.getColor("jLayeredPane1.background")); // NOI18N
        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jLayeredPane1.border.title"))); // NOI18N
        jLayeredPane1.setName("jLayeredPane1"); // NOI18N

        carta1.setName("carta1"); // NOI18N
        carta1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta1ActionPerformed(evt);
            }
        });
        carta1.setBounds(20, 30, 75, 107);
        jLayeredPane1.add(carta1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta2.setName("carta2"); // NOI18N
        carta2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta2ActionPerformed(evt);
            }
        });
        carta2.setBounds(140, 30, 75, 107);
        jLayeredPane1.add(carta2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta3.setName("carta3"); // NOI18N
        carta3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta3ActionPerformed(evt);
            }
        });
        carta3.setBounds(260, 30, 75, 107);
        jLayeredPane1.add(carta3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta4.setName("carta4"); // NOI18N
        carta4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta4ActionPerformed(evt);
            }
        });
        carta4.setBounds(380, 30, 75, 107);
        jLayeredPane1.add(carta4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta6.setName("carta6"); // NOI18N
        carta6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta6ActionPerformed(evt);
            }
        });
        carta6.setBounds(20, 170, 75, 107);
        jLayeredPane1.add(carta6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta7.setName("carta7"); // NOI18N
        carta7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta7ActionPerformed(evt);
            }
        });
        carta7.setBounds(140, 170, 75, 107);
        jLayeredPane1.add(carta7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta8.setName("carta8"); // NOI18N
        carta8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta8ActionPerformed(evt);
            }
        });
        carta8.setBounds(260, 170, 75, 107);
        jLayeredPane1.add(carta8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta9.setName("carta9"); // NOI18N
        carta9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta9ActionPerformed(evt);
            }
        });
        carta9.setBounds(380, 170, 75, 107);
        jLayeredPane1.add(carta9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta10.setName("carta10"); // NOI18N
        carta10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta10ActionPerformed(evt);
            }
        });
        carta10.setBounds(490, 170, 75, 107);
        jLayeredPane1.add(carta10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        carta5.setName("carta5"); // NOI18N
        carta5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carta5ActionPerformed(evt);
            }
        });
        carta5.setBounds(490, 30, 75, 107);
        jLayeredPane1.add(carta5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        start.setText(resourceMap.getString("start.text")); // NOI18N
        start.setName("start"); // NOI18N
        start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startActionPerformed(evt);
            }
        });

        cartaTrunfo.setName("cartaTrunfo"); // NOI18N
        cartaTrunfo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cartaTrunfoActionPerformed(evt);
            }
        });

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jLayeredPane2.border.title"))); // NOI18N
        jLayeredPane2.setName("jLayeredPane2"); // NOI18N

        jogada1.setName("jogada1"); // NOI18N
        jogada1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jogada1ActionPerformed(evt);
            }
        });
        jogada1.setBounds(250, 160, 75, 107);
        jLayeredPane2.add(jogada1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jogada2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jogada2ActionPerformed1(evt);
            }
        });
        jogada2.setBounds(250, 40, 75, 107);
        jLayeredPane2.add(jogada2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jogada3.setName("jogada3"); // NOI18N
        jogada3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jogada3ActionPerformed(evt);
            }
        });
        jogada3.setBounds(90, 100, 75, 107);
        jLayeredPane2.add(jogada3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jogada4.setName("jogada4"); // NOI18N
        jogada4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jogada4ActionPerformed(evt);
            }
        });
        jogada4.setBounds(390, 100, 75, 107);
        jLayeredPane2.add(jogada4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        nome1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nome1.setText(resourceMap.getString("nome1.text")); // NOI18N
        nome1.setName("nome1"); // NOI18N
        nome1.setBounds(230, 270, 110, 16);
        jLayeredPane2.add(nome1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        nome2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nome2.setText(resourceMap.getString("nome2.text")); // NOI18N
        nome2.setName("nome2"); // NOI18N
        nome2.setBounds(230, 10, 110, 16);
        jLayeredPane2.add(nome2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        nome3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nome3.setText(resourceMap.getString("nome3.text")); // NOI18N
        nome3.setName("nome3"); // NOI18N
        nome3.setBounds(70, 220, 110, 16);
        jLayeredPane2.add(nome3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        nome4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nome4.setText(resourceMap.getString("nome4.text")); // NOI18N
        nome4.setName("nome4"); // NOI18N
        nome4.setBounds(370, 220, 110, 16);
        jLayeredPane2.add(nome4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        vez.setText(resourceMap.getString("vez.text")); // NOI18N
        vez.setName("vez"); // NOI18N

        nomeDonoTrunfo.setText(resourceMap.getString("nomeDonoTrunfo.text")); // NOI18N
        nomeDonoTrunfo.setName("nomeDonoTrunfo"); // NOI18N

        vez1.setText(resourceMap.getString("vez1.text")); // NOI18N
        vez1.setName("vez1"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLayeredPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 589, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLayeredPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 95, Short.MAX_VALUE)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(nomeDonoTrunfo)
                                .add(cartaTrunfo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 75, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(91, 91, 91))
                        .add(layout.createSequentialGroup()
                            .add(18, 18, 18)
                            .add(vez, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 223, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap()))
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(start, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 83, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(vez1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 223, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(vez)
                .add(6, 6, 6)
                .add(vez1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(start)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 392, Short.MAX_VALUE)
                .add(nomeDonoTrunfo)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cartaTrunfo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(25, 25, 25))
            .add(layout.createSequentialGroup()
                .add(jLayeredPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
                .add(18, 18, 18)
                .add(jLayeredPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 290, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLayeredPane1.getAccessibleContext().setAccessibleName(resourceMap.getString("jLayeredPane1.AccessibleContext.accessibleName")); // NOI18N

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void carta1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta1ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(0));
            vez.setText("");
        } catch (RemoteException ex) {
                ex.printStackTrace();
        }
    }//GEN-LAST:event_carta1ActionPerformed

    private void carta2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta2ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(1));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta2ActionPerformed

    private void carta3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta3ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(2));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta3ActionPerformed

    private void carta4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta4ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(3));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta4ActionPerformed

    private void cartaTrunfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cartaTrunfoActionPerformed

    }//GEN-LAST:event_cartaTrunfoActionPerformed

    private void carta6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta6ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(5));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta6ActionPerformed

    private void carta7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta7ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(6));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta7ActionPerformed

    private void carta8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta8ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(7));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta8ActionPerformed

    private void carta9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta9ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(8));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta9ActionPerformed

    private void carta10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta10ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(9));
            vez.setText("");
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta10ActionPerformed

    private void startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startActionPerformed
        jogo.iniciar();
        this.start.setVisible(false);
        this.cartaTrunfo.setVisible(false);
        this.nomeDonoTrunfo.setText("TRUNFO: "+jogo.getTrunfo().nipeToString(jogo.getTrunfo().getNipe()));
    }//GEN-LAST:event_startActionPerformed

    private void carta5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carta5ActionPerformed
        try {
            this.jogador.escolheJogada(cartas.get(4));
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_carta5ActionPerformed

    private void jogada1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jogada1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jogada1ActionPerformed

    private void jogada2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jogada2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jogada2ActionPerformed

    private void jogada3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jogada3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jogada3ActionPerformed

    private void jogada4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jogada4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jogada4ActionPerformed

    private void jogada2ActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jogada2ActionPerformed1
        // TODO add your handling code here:
    }//GEN-LAST:event_jogada2ActionPerformed1

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]){
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new TelaJogo(null,null).setVisible(true);
                } catch (RemoteException ex) {
                    ex.printStackTrace();
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton carta1;
    private javax.swing.JButton carta10;
    private javax.swing.JButton carta2;
    private javax.swing.JButton carta3;
    private javax.swing.JButton carta4;
    private javax.swing.JButton carta5;
    private javax.swing.JButton carta6;
    private javax.swing.JButton carta7;
    private javax.swing.JButton carta8;
    private javax.swing.JButton carta9;
    private javax.swing.JButton cartaTrunfo;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JButton jogada1;
    private javax.swing.JButton jogada2;
    private javax.swing.JButton jogada3;
    private javax.swing.JButton jogada4;
    private javax.swing.JLabel nome1;
    private javax.swing.JLabel nome2;
    private javax.swing.JLabel nome3;
    private javax.swing.JLabel nome4;
    private javax.swing.JLabel nomeDonoTrunfo;
    private javax.swing.JButton start;
    private javax.swing.JLabel vez;
    private javax.swing.JLabel vez1;
    // End of variables declaration//GEN-END:variables

    private int countRodada=0;
    public void update(Observable o, Object o1) {
        Jogador jogador;
        if(o1 instanceof AlertaVencedor){
            try {
                jogador = ((AlertaVencedor)o1).getVencedor();
                vez.setText("O jogador "+jogador.getNome()+" venceu!");
                countRodada++;
            } catch (RemoteException ex) {
                ex.printStackTrace();
            }

        } else if(o1 instanceof InicioRodada) {
            jogo.getRodadaAtual().addObserver(this);
            jogada1.setIcon(new ImageIcon(this.imgFolder+"back-blue-75-2.png"));
            nome1.setText("");
            jogada2.setIcon(new ImageIcon(this.imgFolder+"back-blue-75-2.png"));
            nome2.setText("");
            jogada2.setIcon(new ImageIcon(this.imgFolder+"back-blue-75-2.png"));
            nome2.setText("");
            jogada3.setIcon(new ImageIcon(this.imgFolder+"back-blue-75-2.png"));
            nome3.setText("");
            jogada4.setIcon(new ImageIcon(this.imgFolder+"back-blue-75-2.png"));
            nome4.setText("");
        }else if(o instanceof Rodada && o1 instanceof AlertaVez){
            jogador = ((AlertaVez)o1).getJogador();
            if(jogador==this.jogador){
                try {
                    System.out.println("Sua vez!");
                    vez.setText("Sua vez, "+jogador.getNome()+"!");
                } catch (RemoteException ex) {
                    ex.printStackTrace();
                }
            }else{
                vez.setText("Aguarde sua vez!");
            }
        }else if(o1 instanceof AlertaJogada){
            try {
                jogador = ((AlertaJogada)o1).getJogada().getJogador();
                if(jogador==this.jogador.getTime().getJogador2()){
                    jogada2.setIcon(new ImageIcon(imgFolder+((AlertaJogada)o1).getJogada().getCartaJogada().imageURL()));
                    nome2.setText(((AlertaJogada)o1).getJogada().getJogador().getNome());
                }else if(jogador==this.jogador){
                    jogada1.setIcon(new ImageIcon(imgFolder+((AlertaJogada)o1).getJogada().getCartaJogada().imageURL()));
                    nome1.setText(((AlertaJogada)o1).getJogada().getJogador().getNome());
                }else if(jogador==this.jogo.getTimeB().getJogador1()){
                    jogada3.setIcon(new ImageIcon(imgFolder+((AlertaJogada)o1).getJogada().getCartaJogada().imageURL()));
                    nome3.setText(((AlertaJogada)o1).getJogada().getJogador().getNome());
                }else{
                    jogada4.setIcon(new ImageIcon(imgFolder+((AlertaJogada)o1).getJogada().getCartaJogada().imageURL()));
                    nome4.setText(((AlertaJogada)o1).getJogada().getJogador().getNome());
                }
                //jogada1 = new JButton(new ImageIcon(imgFolder+jogo.getTrunfo().imageURL()));
                
                if(((AlertaJogada)o1).getJogada().getJogador()==this.jogador){
                    int k=-1;
                    for(int i=0;i<cartas.size();i++)
                        if(cartas.get(i).getNipe()==(((AlertaJogada)o1).getJogada().getCartaJogada()).getNipe()
                        && cartas.get(i).getNumero()==(((AlertaJogada)o1).getJogada().getCartaJogada()).getNumero()){
                            k=i;
                            break;
                        }
                    
                    switch(k){
                        case 0:
                            carta1.setVisible(false);
                            break;
                        case 1:
                            carta2.setVisible(false);
                            break;
                        case 2:
                            carta3.setVisible(false);
                            break;
                        case 3:
                            carta4.setVisible(false);
                            break;
                        case 4:
                            carta5.setVisible(false);
                            break;
                        case 5:
                            carta6.setVisible(false);
                            break;
                        case 6:
                            carta7.setVisible(false);
                            break;
                        case 7:
                            carta8.setVisible(false);
                            break;
                        case 8:
                            carta9.setVisible(false);
                            break;
                        case 9:
                            carta10.setVisible(false);
                            break;
                    }
                }


                pack();
            } catch (RemoteException ex) {
                ex.printStackTrace();
            }
        }else if (o instanceof Rodada && o1 instanceof FimRodada){
            System.out.println("Rodada Final: "+countRodada);
            if(countRodada>=10){
                if(jogo.getTimeA().getPontos()>jogo.getTimeB().getPontos()){
                    try {
                        vez.setText("Vencedores ("+jogo.getTimeA().getPontos()+" pts / "+jogo.getTimeB().getPontos()+" pts): ");
                        vez1.setText(jogo.getTimeA().getJogador1().getNome()+", "+jogo.getTimeA().getJogador2().getNome());
                    } catch (RemoteException ex) {
                        ex.printStackTrace();
                    }
                }else if(jogo.getTimeA().getPontos() < jogo.getTimeB().getPontos()){
                    try {
                        vez.setText("Vencedores ("+jogo.getTimeB().getPontos()+" pts / "+jogo.getTimeA().getPontos()+" pts): ");
                        vez1.setText(jogo.getTimeB().getJogador1().getNome()+", "+jogo.getTimeB().getJogador2().getNome());
                    } catch (RemoteException ex) {
                        ex.printStackTrace();
                    }
                }else if(jogo.getTimeA().getPontos() == jogo.getTimeB().getPontos()){
                        vez.setText("Empate ("+jogo.getTimeA().getPontos()+" pts)!");
                }
            }
        }       
    }
}

